<template>
  <div>
    <el-form :inline="true" :model="queryForm" @keyup.enter.native="getDataList()">
      <el-form-item label="签到时间">
        <el-date-picker v-model="timeArr" value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="queryForm.mobile" oninput="if(value.length>11)value=value.slice(0,11)" :maxlength="11" type="number" placeholder="用户手机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getDataList()">查询</el-button>
        <el-button icon="el-icon-refresh-left" @click="reset">重置</el-button>
      </el-form-item>
      <el-form-item label="仅含奖励">
        <el-switch v-model="queryForm.isWithBonus" :active-value="1" :inactive-value="0" @change="getDataList()">
        </el-switch>
      </el-form-item>
    </el-form>

    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column align="center" label="序号" width="180">
        <template slot-scope="scope">
          <span>{{(queryForm.page - 1) * queryForm.limit + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="user_id" header-align="center" align="center" label="用户">
        <template slot-scope="{row}">
          {{row.username}}({{row.mobile}})
        </template>
      </el-table-column>
      <el-table-column prop="sign_in_time" header-align="center" align="center" label="签到时间">
      </el-table-column>
      <el-table-column prop="integral" header-align="center" align="center" label="发放爱心值">
      </el-table-column>
      <el-table-column prop="coupon_name" header-align="center" align="center" label="满勤奖励">
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="queryForm.page" :page-sizes="[10, 20, 50, 100]" :page-size="queryForm.limit" :total="total" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
import signInApi from '@/api/signInApi.js'
export default {
  data () {
    return {
      queryForm: {
        limit: 10,
        page: 1,
      },
      total: 0,
      dataListLoading: false,
      dataList: [],
      timeArr: []
    }
  },
  created () {
    this.getDataList()
  },
  methods: {
    getDataList () {
      signInApi.signInPage(this.queryForm).then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.page.list;
          this.total = res.data.page.totalCount;
        }
        this.dataListLoading = false;
      })
    },
    reset () {
      this.queryForm = {
        limit: 10,
        page: 1,
      }
      this.timeArr = [];
      this.getDataList()
    },
    timeChange (e) {
      if (e && e.length > 0) {
        this.queryForm.startTime = e[0];
        this.queryForm.endTime = e[1];
      } else {
        this.queryForm.startTime = null;
        this.queryForm.endTime = null;
      }
    },
    // 每页数
    sizeChangeHandle (val) {
      this.queryForm.limit = val
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.queryForm.page = val
      this.getDataList()
    },
  }
}
</script>

<style>
.el-form--inline .el-form-item__content {
  width: auto !important;
}
input[type='number'] {
  -moz-appearance: textfield;
}
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
  -webkit-appearance: none;
}
</style>
<style>
</style>